<div class="box white_bg">
<? if (!$this->viewParams['gallery']) :?>
<?=t(6104)?> 
<?else:?>
<style type="text/css">
   .frame{
      width:690px;
	  height:auto;
   }
   
   .frame_img{
   	  border:1px solid white;
      width:205px;
	  height:150px;
	  margin:2px 10px;
	  float:left; 
   }
   .frame_img img{
      width:100px;
	  height:100px;
	  margin:0 auto;
	  border:1px #CCCCCC solid;
	  padding:3px;
   }
   .clear{
      clear:both; 
   }
   a{
       text-decoration:none;   
    }
   .frame_title{
     margin:4px auto; 
   }
   .frame_title  a.img_title{
     font:13px Arial, Helvetica, sans-serif;
	 color:#0033CC;
   }
    .frame_title a.img_title:hover{
	 color:#CC0000;
   }
</style>
<script type="text/javascript" src="/public/library/jquery/prettyPhoto/jquery.prettyPhoto.js"></script>
<link rel="stylesheet" href="/public/library/jquery/prettyPhoto/prettyPhoto.css" type="text/css" media="screen" title="prettyPhoto main stylesheet" charset="utf-8" />
<br/>
<br/>

<?
	$sess= new Zend_Session_Namespace(CLU_NS);
	if (!empty($this->viewParams['gallery']['images'])) :?>

<div class="frame">
	<?
	$images = unserialize($this->viewParams['gallery']['images']);
	//die_a($images);
	foreach ($images as $image):?>
	
	<div class="frame_img" align="center">
	<a href="<?=$image['filename']?>" rel="prettyPhoto[gallery]" 
	title="<?=$image['title'] ?>">
	<img src="<?=str_replace("/original/", "/small/", $image['filename']) ?>" align="absmiddle" />
	</a>
	<div class="clear"></div>
	<a href="#" class="img_title"><?=$image['title'] ?></a> 
	<div class="frame_title" style="display:none;">
		<?
			if (strpos($sess->userPermissions, 'update gallery') || $sess->userId == $this->viewParams['gallery']['poster_id']) :?>

		<span style="font-size:9px;"> (<a href="javascript:void()" title="<?=$image['filename']?>" class="title_edit"><?=t(38)?> <?=t(810)?></a> |
		<a href="javascript:void()" class="set-thumb" title="<?=$image['filename']; ?>"><?=t(6103)?> </a>
		
		| <a href="javascript:void()" class="delete-image" title="<?=$image['filename']; ?>"><?=t(5006)?> </a>
		)
		</span>
		<?endif ?>		
	</div>
	</div>
	
	<?endforeach ?>
</div>
	<script type="text/javascript">
		$(document).ready(function() {

			$("div.frame_img").hover(
				function(){
					$(this).css({"border-color" : "blue", "background-color" : "#c3c5d1"});
					$(this).find(".frame_title").show();	
				},
				function(){
					$(this).css({"border-color" : "white", "background-color" : "white"});
					$(this).find(".frame_title").hide();	
				});
		});

			$("a[rel^='prettyPhoto']").prettyPhoto();

		</script>
		
		<?if (strpos($sess->userPermissions, 'update gallery') || $sess->userId == $this->viewParams['gallery']['poster_id']) :?>
		<!--  If upload mode -->
		<script type="text/javascript">
		$(function(){
//			console.log('23');
//			alert('233);

		});
		
		$(document).ready(function() {
			$("a.delete-image").click(function(){
				$frame = $(this).parent().parent().parent();
				id = <?=$this->viewParams['gallery']['id']?>;
				filename =  $(this).attr('title');
				$.getJSON("<?=$this->hvnUrl(array("module" => 'gallery',
												 'action'=> "delete-image",
												 "controller" => "ajax"), "generic")?>", 
						{"id": id, "filename":filename},
						function(json)
						{
							if (json.success)
							{
								$frame.css("background-color", "red").fadeOut(500);
							}
							else
								alert("Failed: " + json.errorMessage);		
						}
				);
			});
			
			$("a.title_edit").click(function(){
				$frame = $(this).parent().parent().parent();
				//alert('1332');
				var oldTitle = $frame.find("a.img_title").html();
				var newTitle = window.prompt("Enter new image name", oldTitle);
				if (oldTitle != newTitle && newTitle != null)
				{
					id = <?=$this->viewParams['gallery']['id']?>;
					filename =  $(this).attr('title');
					
					$.getJSON("<?=$this->hvnUrl(array("module" => 'gallery',
												 'action'=> "update-image-title",
												 "controller" => "ajax"), "generic")?>", 
						{"id": id, "filename":filename, "title": newTitle},
						function(json)
						{
							if (json.success)
							{
								$frame.find("a.img_title").html(newTitle);
								alert("Title set");
							}
							else
								alert("Failed: " + json.errorMessage);		
						}
					);
				}
			});
			$("a.set-thumb").click(function(){
				id = <?=$this->viewParams['gallery']['id']?>;
				thumb = $(this).attr('title');
				$.getJSON("<?=$this->hvnUrl(array("module" => 'gallery',
											 'action'=> "update-thumb",
											 "controller" => "ajax"), "generic")?>", 
					{"id": id, "thumb":thumb},
					function(json)
					{
						if (json.success)
						{
							alert("Thumbnail set");
						}
						else
							alert("Failed: " + json.errorMessage);		
					}
				);
			});
		});
		</script>
		<?endif ?>
		
<?endif ?>

<?endif ?>
</div>